package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.ContentsDAO;
import entity.Contents;

@WebServlet("/draftcheck")
public class DrafteditServlet extends HttpServlet{
	private ContentsDAO contents=new ContentsDAO();

	 public DrafteditServlet() {
	        super();
	    }

	 public void doGet(HttpServletRequest request, HttpServletResponse response)
	            throws ServletException, IOException {
	        doPost(request,response);
	    }
	 public void doPost(HttpServletRequest request, HttpServletResponse response)
	            throws ServletException, IOException {
		  request.setCharacterEncoding("utf-8");
		  String method = request.getParameter("method");
		  modifyContents(request);
		  request.setAttribute("userno", request.getParameter("userno"));
	      request.getRequestDispatcher("/draftList.jsp").forward(request, response);   	
	  }

	private void modifyContents(HttpServletRequest request) {
		try {
			Contents contents=new Contents();
			contents.setCno(request.getParameter("cno"));
			contents.setCname(request.getParameter("cname"));
			contents.setCcompany(request.getParameter("ccompany"));
			contents.setPrice1(request.getParameter("price1"));
			contents.setPrice2(request.getParameter("price2"));
			contents.setPrice3(request.getParameter("price3"));
			contents.setCprice(request.getParameter("cprice"));
			contents.setPaystate(request.getParameter("paystate"));
			contents.setPaytimes(request.getParameter("paytimes"));
			contents.setMclause(request.getParameter("mclause"));
			contents.setCstart(request.getParameter("cstart"));
			contents.setCend(request.getParameter("cend"));
			contents.setOther(request.getParameter("other"));			
			this.contents.contents_editsave(contents);
	        
		 } catch (Exception ex) {
			 
	         request.setAttribute("errormsg", ex.getMessage());
	         
	     }
	}

}
